package com.tedu.parkinglot.role.service.impl;

import com.tedu.parkinglot.role.mapper.RoleMapper;
import com.tedu.parkinglot.role.pojo.dto.RoleQuery;
import com.tedu.parkinglot.role.pojo.dto.RoleSaveParam;
import com.tedu.parkinglot.role.pojo.entity.Role;
import com.tedu.parkinglot.role.pojo.vo.RoleVO;
import com.tedu.parkinglot.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class RoleServiceImpl implements RoleService {


    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<RoleVO> selectRole(RoleQuery roleQuery) {
        log.debug("查询参数{}", roleQuery);
        List<RoleVO> list =roleMapper.roleSelect(roleQuery);
         return list;
    }

    @Override
    public void save(RoleSaveParam roleSaveParam) {
        log.debug("新增参数{}", roleSaveParam);
        Role role = new Role();
        BeanUtils.copyProperties(roleSaveParam, role);
        if (role.getId()==null){
           role.setAdminId(1L);
           role.setParkingId(1L);
          roleMapper.insert(role);
        }else if (role.getId()!=null){
            log.debug("修改参数{}", role);
            roleMapper.update(role);
        }

    }

    @Override
    public void delete(Long id) {
        log.debug("删除参数{}", id);
        roleMapper.delete(id);
    }
}
